//
// Created by shiminli on 2024/1/3.
//

#ifndef DDOFFICE_VERIFY_CODES_H
#define DDOFFICE_VERIFY_CODES_H

#include <iostream>
#include "../SQLHelper.h"
#include "../SQLBuilder.h"
#include <mysql/mysql.h>
#include <vector>
#include <optional>
#include "hv/httpdef.h"
#include "hv/HttpService.h"

using namespace std;
using namespace ddoffice;

/**
 CREATE TABLE `verify_codes` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `phone_number` char(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `platform` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `verify_code` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `duration` int DEFAULT NULL,
  `used` tinyint(1) DEFAULT NULL,
  `create_time` datetime(3) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
 */
 struct VerifyCodes{
     long id;
     string phone_number;
     string platform;
     string verify_code;
     int duration;
     int used;
     string create_time;

 };
struct VerifyCodesColumnName{
    string tabName = "verify_codes";
    string id = "id";
    string phone_number= "phone_number";
    string platform= "platform";
    string verify_code= "verify_code";
    string duration= "duration";
    string used= "used";
    string create_time= "create_time";

};

class verify_codes {

public:
    static VerifyCodesColumnName names;
    static vector<string> columns ;
    static long insert(VerifyCodes &data);
    static int updateUseByCode(string verify_code);
    static std::optional<VerifyCodes> queryById(const long &user_id);
    static std::optional<VerifyCodes> queryByPhoneNumber(const string &phone_number);

    static void rowToStruct(const MYSQL_ROW &row, VerifyCodes &acc);

};


#endif //DDOFFICE_VERIFY_CODES_H
